package com.ruoyi.web.controller.linkage.linkageStrategy;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.linkage.Vo.LinkageStrategyVo;
import com.ruoyi.linkage.domain.LinkageAuthorize;
import com.ruoyi.linkage.domain.LinkagePlcConf;
import com.ruoyi.linkage.service.ILinkagePlcConfService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单机PLC控制逻辑配置Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/linkage/PicConf")
public class LinkagePlcConfController extends BaseController
{
    @Autowired
    private ILinkagePlcConfService linkagePlcConfService;

    /**
     * 查询单机PLC控制逻辑配置列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:list')")
    @GetMapping("/list")
//    public PageInfo<LinkagePlcConf> list(LinkageStrategyVo linkageStrategyVo)
//    {
//        PageInfo<LinkagePlcConf> pageInfo=linkagePlcConfService.selectPage(linkageStrategyVo);
//        return pageInfo;
//    }
    public  TableDataInfo list(LinkageStrategyVo linkageStrategyVo)
    {
        PageHelper.startPage(Integer.parseInt(linkageStrategyVo.getPageNum()),Integer.parseInt(linkageStrategyVo.getPageSize()));
        LinkagePlcConf linkagePlcConf=new LinkagePlcConf();
        List<LinkagePlcConf> list=linkagePlcConfService.selectLinkagePlcConfList(linkagePlcConf);
        return  getDataTable(list);
    }


    /**
     * 导出单机PLC控制逻辑配置列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:export')")
    @Log(title = "单机PLC控制逻辑配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkagePlcConf linkagePlcConf)
    {
        List<LinkagePlcConf> list = linkagePlcConfService.selectLinkagePlcConfList(linkagePlcConf);
        ExcelUtil<LinkagePlcConf> util = new ExcelUtil<LinkagePlcConf>(LinkagePlcConf.class);
        util.exportExcel(response, list, "单机PLC控制逻辑配置数据");
    }

    /**
     * 获取单机PLC控制逻辑配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(linkagePlcConfService.selectLinkagePlcConfById(id));
    }

    /**
     * 新增单机PLC控制逻辑配置
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:add')")
    @Log(title = "单机PLC控制逻辑配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkagePlcConf linkagePlcConf)
    {
        return toAjax(linkagePlcConfService.insertLinkagePlcConf(linkagePlcConf));
    }

    /**
     * 修改单机PLC控制逻辑配置
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:edit')")
    @Log(title = "单机PLC控制逻辑配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkagePlcConf linkagePlcConf)
    {
        return toAjax(linkagePlcConfService.updateLinkagePlcConf(linkagePlcConf));
    }

    /**
     * 删除单机PLC控制逻辑配置
     */
    @PreAuthorize("@ss.hasPermi('linkage:conf:remove')")
    @Log(title = "单机PLC控制逻辑配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(linkagePlcConfService.deleteLinkagePlcConfByIds(ids));
    }
}
